/*
 * HourGlass.java
 *
 * Created on December 12, 2006, 9:25 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package eu.somatik.somaftp.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.Timer;

/**
 *
 * @author francisdb
 */
public class HourGlass{
    
    private static final String[] views = new String[]{
        "/  ",
        " / ",
        "  /"
    };
    
    private Timer timer;
    
    private int index;
    
    private JLabel label;
    
    /** Creates a new instance of HourGlass */
    public HourGlass(JLabel label) {
        
        timer = new Timer(100, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                update();
            }
        });
        this.label = label;
        this.index = 1;
    }
    
    public void start(){
        timer.start();
    }
    
    public void stop(){
        timer.stop();
    }

    private void update(){
        label.setText(views[index]);
        index++;
        index = index % views.length;
    }
    

    
}
